/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package br.com.menosehmais.persistence;

import br.com.caelum.vraptor.ioc.Component;
import br.com.menosehmais.framework.persistence.DaoJpa2;
import br.com.menosehmais.model.PortletViewDO;
import javax.persistence.EntityManager;
import javax.persistence.TypedQuery;

/**
 *
 * @author Junior JAFJ
 */
@Component
public class ViewPortletDAO extends DaoJpa2<PortletViewDO>{

    public ViewPortletDAO(EntityManager em) {
        super(PortletViewDO.class, em);
    }

    public long countByUserId(String userId) {
        String jpql = "SELECT COUNT(id) FROM PortletViewDO pv WHERE pv.account.id = :userId";

        TypedQuery<Long> query = entityManager.createQuery(jpql, Long.class);
        query.setParameter("userId", userId);
        long result = query.getSingleResult();

        return result;
    }
    
}
